package com.jt.safe.ui.parent.fragment


import android.content.Intent
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.LayoutMode
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.lifecycle.lifecycleOwner
import com.jt.safe.R
import com.jt.safe.base.BaseFragment
import com.jt.safe.entity.SelectStudentBean
import com.jt.safe.ui.adpter.SelectStudentAdapter
import com.jt.safe.ui.parent.activity.BindingStudentActivity
import com.jt.safe.ui.parent.activity.SettingActivity
import com.jt.safe.viewmodel.NullViewModel
import kotlinx.android.synthetic.main.fragment_parent_mine.*

class ParentMineFragment : BaseFragment<NullViewModel>() {
    val students = mutableListOf<SelectStudentBean>()

    companion object {
        fun newInstance() = ParentMineFragment()
    }

    override val layoutId: Int
        get() = R.layout.fragment_parent_mine

    override fun createObserver() {
        students.add(SelectStudentBean("王大明", true))
        students.add(SelectStudentBean("王小明", false))
        students.add(SelectStudentBean("继续绑定学生", false))
    }

    override fun initView() {
        setting.setOnClickListener { startActivity(Intent(activity, SettingActivity::class.java)) }
        ll2.setOnClickListener {
            activity?.let {
                MaterialDialog(it, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
                    val inflate = layoutInflater.inflate(R.layout.select_student, null, false)
                    customView(null, inflate)
                    val recycler = inflate.findViewById<RecyclerView>(R.id.recycler)
                    val selectStudentAdapter = SelectStudentAdapter()
                    recycler.layoutManager= LinearLayoutManager(activity)
                    recycler.adapter = selectStudentAdapter
                    selectStudentAdapter.setNewData(students)
                    lifecycleOwner(this@ParentMineFragment)
                    selectStudentAdapter.setOnItemClickListener { adapter, view, position ->
                        startActivity(Intent(activity,BindingStudentActivity::class.java))
                    }
                }
            }
        }
    }

    override fun initData() {

    }
}